package com.ifood.system.service.impl;

import java.util.List;

import com.ifood.common.constant.CacheConstants;
import com.ifood.common.core.domain.entity.FoodProductCategory;
import com.ifood.common.core.domain.vo.ProductCategoryVo;
import com.ifood.common.core.redis.RedisCache;
import com.ifood.common.utils.DateUtils;
import com.ifood.system.mapper.FoodProductCategoryMapper;
import com.ifood.system.service.IFoodProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商品分类Service业务层处理
 *
 * @author ifood
 * @date 2024-01-14
 */
@Service
public class FoodProductCategoryServiceImpl implements IFoodProductCategoryService {
    @Autowired
    private FoodProductCategoryMapper foodProductCategoryMapper;
    @Autowired
    private RedisCache redisCache;

    /**
     * 查询商品分类
     *
     * @param categoryId 商品分类主键
     * @return 商品分类
     */
    @Override
    public FoodProductCategory selectFoodProductCategoryByCategoryId(Long categoryId) {
        return foodProductCategoryMapper.selectFoodProductCategoryByCategoryId(categoryId);
    }

    /**
     * 查询商品分类列表
     *
     * @param foodProductCategory 商品分类
     * @return 商品分类
     */
    @Override
    public List<FoodProductCategory> selectFoodProductCategoryList(FoodProductCategory foodProductCategory) {
        return foodProductCategoryMapper.selectFoodProductCategoryList(foodProductCategory);
    }

    /**
     * 新增商品分类
     *
     * @param foodProductCategory 商品分类
     * @return 结果
     */
    @Override
    public int insertFoodProductCategory(FoodProductCategory foodProductCategory) {
        Long increment = redisCache.getIncrement(CacheConstants.Category.CATEGORY_SN);
        foodProductCategory.setCategoryType(increment);
        foodProductCategory.setCreateTime(DateUtils.getNowDate());
        return foodProductCategoryMapper.insertFoodProductCategory(foodProductCategory);
    }

    /**
     * 修改商品分类
     *
     * @param foodProductCategory 商品分类
     * @return 结果
     */
    @Override
    public int updateFoodProductCategory(FoodProductCategory foodProductCategory) {
        foodProductCategory.setUpdateTime(DateUtils.getNowDate());
        return foodProductCategoryMapper.updateFoodProductCategory(foodProductCategory);
    }

    /**
     * 批量删除商品分类
     *
     * @param categoryIds 需要删除的商品分类主键
     * @return 结果
     */
    @Override
    public int deleteFoodProductCategoryByCategoryIds(Long[] categoryIds) {
        return foodProductCategoryMapper.deleteFoodProductCategoryByCategoryIds(categoryIds);
    }

    /**
     * 删除商品分类信息
     *
     * @param categoryId 商品分类主键
     * @return 结果
     */
    @Override
    public int deleteFoodProductCategoryByCategoryId(Long categoryId) {
        return foodProductCategoryMapper.deleteFoodProductCategoryByCategoryId(categoryId);
    }

    @Override
    public List<ProductCategoryVo> selectProductCategories() {
        return foodProductCategoryMapper.getProductCategories();
    }
}
